<%@ page language="java" import="com.sap.mw.jco.IFunctionTemplate" pageEncoding="UTF-8" %>
<%@page import="com.sap.mw.jco.JCO" %>
<%@page import="com.weaver.integration.datesource.SAPInterationOutUtil" %>
<%@page import="com.weaver.integration.log.LogInfo" %>
<%@page import="weaver.general.Util" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="weaver.general.BaseBean" %>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<%
    String json = "{\"flag\":\"0\"}";
    String mbjson = "";
    String matnr = Util.null2String(request.getParameter("matnr"));
    Map<String, String> map1 = new HashMap<>();
    map1.put("MATNR", matnr);
    bb.writeLog("MATNR="+matnr);
    JCO.Table tabs = ZBPM_PR_HELP_1_execute(map1);
    for (int i = 0; i < tabs.getNumRows(); i++) {
        tabs.setRow(i);
        String txz01 = Util.null2String(tabs.getValue("TXZ01"));//短文本
        String ebeln = Util.null2String(tabs.getValue("EBELN"));//采购凭证号
        String bedat = Util.null2String(tabs.getValue("BEDAT"));//订单日期
        String menge = Util.null2String(tabs.getValue("MENGE"));//采购订单数量
        String meins = Util.null2String(tabs.getValue("MEINS"));//采购订单的计量单位
        String netpr = Util.null2String(tabs.getValue("NETPR"));//净价
        String waers = Util.null2String(tabs.getValue("WAERS"));//货币码
        String str ="{\"txz01\":\"" + txz01 + "\",\"ebeln\":\"" + ebeln + "\",\"bedat\":\"" + bedat + "\",\"menge\":\""+
                menge+"\",\"meins\":\"" + meins + "\",\"netpr\":\"" + netpr + "\",\"waers\":\"" + waers + "\"}";
        if("".equals(mbjson)){
            mbjson = str;
        }else{
            mbjson += ","+str;
        }
    }
    if (!"".equals(mbjson)) {
        json="{\"flag\":\"1\",\"mb\":["+mbjson+"]}";
    }
     bb.writeLog("wlcgjl="+json.toString());
    out.print(json);
%>
<%!
    public static JCO.Table ZBPM_PR_HELP_1_execute(Map<String, String> map) {
        SAPInterationOutUtil outUtil = new SAPInterationOutUtil();
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog("in---ZBPM_PR_HELP_1_execute()");
        JCO.Client myConnection = (JCO.Client) outUtil.getConnection("2", new LogInfo());
        myConnection.connect();
        JCO.Repository myRepository = new JCO.Repository("Repository", myConnection); // 只一个名字
        IFunctionTemplate ft = myRepository.getFunctionTemplate("ZBPM_PR_HELP_1_NEW");//设置BAPI函数
        JCO.Function bapi = ft.getFunction();
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理
        //输入参数
        input.setValue(map.get("MATNR"), "MATNR");
        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        JCO.Table tabs = Table00.getTable("IT_FILE");
        baseBean.writeLog("SPA_COUNTS:" + tabs.getNumRows());
        //返回处理结果以及日志
        JCO.releaseClient(myConnection);
        return tabs;
    }
%>
